package com.agile.java_seetaface.sqlite;



import java.sql.*;
import java.time.LocalDate;

/**
 * @Author ChenZhangKun
 * @Date 2020/5/13 15:50
 */
public class OpenSqlite {
    // 驱动包名
    private static final String class_name="org.sqlite.JDBC";
    // 数据库地址
    private static final String db_path="jdbc:sqlite:D:\\czk\\java_seetaface\\seetafaceJNI\\doc\\person.db";
    public static void main(String[] args) throws SQLException {
        Person.get();
        Connection connection = createConnection();
        String sql="insert into person('name','age') values(?,?)";
        int b=insert(sql,connection);
        if (b==1){
            System.out.println("插入成功,日期是2020年的第"+ LocalDate.now().getDayOfYear()+"天");
        }

    }
    public static Connection createConnection() throws SQLException {
        try {
            // 注册驱动
            Class.forName(class_name);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        // 返回连接
        System.out.println(DriverManager.class.getClassLoader());
        return DriverManager.getConnection(db_path);
    }
    public static int insert(String sql,Connection connection) throws SQLException {
        // 执行sql
        PreparedStatement statement = connection.prepareStatement(sql);
        // 设置参数
        statement.setObject(1,"林俊杰");
        statement.setObject(2,42);
        return  statement.executeUpdate();
    }
    public void get(){
        //
        System.out.println("反射调用");
    }
}
